package io.polly.ldz.webflux;

import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
import reactor.core.publisher.Mono;
import reactor.netty.http.server.HttpServer;

import java.io.IOException;

public class FluxMainApplication {


    public static void main(String[] args) throws IOException {

        HttpHandler handler = (request, response)->{

            System.out.println(request.getURI());
            DataBufferFactory dbf= response.bufferFactory();
            Mono<DataBuffer> mono = Mono.just(dbf.wrap("hello".getBytes()));

            return response.writeWith(mono);
//            return response.setComplete();
//            return Mono.empty();
        };

        ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);

        HttpServer.create().host("localhost").port(8081).handle(adapter).bindNow();

        System.in.read();
    }
}
